package sparkDay2

import org.apache.spark.{SparkConf, SparkContext}

object SparkDemoTwo {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setMaster("local[*]").setAppName("urlWordcount")

    val sc = new SparkContext(conf)
    sc.setLogLevel("error")

    val textRDD = sc.textFile("D:\\IDEA_Workspace\\Scala Workspace\\2024-2025\\16code\\data\\teacher.log")

    val userRDD = textRDD.map { line =>
      val lastPart = line.split("/").last
      (lastPart, 1)
    }

    val countRDD = userRDD.reduceByKey((x, y) => x + y)

    countRDD.collect().foreach { case (user, count) =>
      println(s"($user,$count)")
    }

    sc.stop()
  }
}
